<?php
include_once(dirname(dirname(__FILE__))."/common/config.inc.php");
$list = array();
$memcache = new Memcache();
$memcache->connect($memcacheConfig[0]['server'],$memcacheConfig[0]['port']);
$allSlabs = $memcache->getExtendedStats('slabs');
$items = $memcache->getExtendedStats('items');
foreach($allSlabs as $server => $slabs) {
	foreach($slabs AS $slabId => $slabMeta) {
		$cdump = $memcache->getExtendedStats('cachedump',(int)$slabId);
		foreach($cdump AS $server => $entries) {
			if($entries) {
				foreach($entries AS $eName => $eData) {
					$list[$eName] = array(
					'key' => $eName,
					'server' => $server,
					'slabId' => $slabId,
					'detail' => $eData,
					'age' => $items[$server]['items'][$slabId]['age'],
					);
				}
			}
		}
	}
}
ksort($list);
$tmp = array();
$db = Factory::getDB('id5_user');
$v_db = Factory::getDB('user_verification');
foreach($list as $key=>$value){
	//$tmp[$key] = $memcache->get($key);
	//$temp_str = substr($key,0,4);
	if(strpos($key,SFT)!==false){
		$array = unserialize($memcache->get($key));
		if($array['state']==1){
			$v_arr['s_id'] = $array['sft'];
			$v_arr['coop_username'] = $array['user_name'];
			$v_arr['coop_user_id'] = $array['user_id'];
			$v_arr['email'] = $array['email'];
			$v_arr['company'] = $array['company'];
			$v_arr['worker'] = $array['position'];
			$v_arr['veri_time'] = $array['time'];
			$v_arr['veri_state'] = 1;
			$v_arr['cooperation_id'] = $array['icpcode'];
			//查询是否已经添加
			$where = "identity_card = '{$array['identity_card']}'";
			$user_arr = $db->getAll($where,'','','','user_id');
			if(isset($user_arr[0])){
				$v_where = "s_id={$array['sft']} and coop_user_id={$array['user_id']} and cooperation_id={$array['icpcode']} and user_id={$user_arr[0]['user_id']}";
				$v_temp_arr = $v_db->getAll($v_where);
				//如果为空则插入
				if(empty($v_temp_arr[0])){
					$v_arr['user_id'] = $user_arr[0]['user_id'];
					if($v_db->insert_user_verification($v_arr)){
						$memcache->delete($key);
					}
				}else{
					$memcache->delete($key);
				}
			}else{
				$u_arr['user_name'] = $array['real_name'];
				$u_arr['identity_card'] = $array['identity_card'];
				$u_arr['user_mob'] = $array['user_mob'];
				$u_arr['user_sex'] = ($array['gender'])=='男'?1:0;
				$u_arr['mob_area'] = $array['phoneArea'];
				$u_arr['astro'] = $array['astro'];
				$u_arr['address'] = $array['addr'];
				$u_arr['age'] = $array['age'];
				$u_arr['animals'] = $array['animals'];
				$u_arr['photo'] = $array['photo'];
				$u_arr['birthday'] = $array['birthday'];
				$u_arr['user_state'] = 1;
				if($uid = $db->insert_id5_user($u_arr)){
					$v_arr['user_id'] = $uid;
					if($v_db->insert_user_verification($v_arr)){
						$memcache->delete($key);
					}
				}
				
			}
		}
	}
}

?>
